package com.andyyan.elasticsearch.client.def.query;

import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.QueryBuilder;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by yantingxin on 16-9-8.
 */
public class ESQueryRequest implements Serializable{

    private static final long serialVersionUID = -4953823923194327178L;

    private String indexName;

    private String typeName;

//    private ESQueryTypeEnum queryType;

    private List<String> highlightFieldList;

    private int offset;

    private int limit;

    private long timeout;//mills

    //
    private QueryBuilder queryBuilder;

    private SearchType searchType = SearchType.DFS_QUERY_THEN_FETCH;

    public ESQueryRequest() {}

    public ESQueryRequest(String indexName, String typeName, List<String> highlightFieldList, int offset, int limit, long timeout, QueryBuilder queryBuilder) {
        this.indexName = indexName;
        this.typeName = typeName;
        this.highlightFieldList = highlightFieldList;
        this.offset = offset;
        this.limit = limit;
        this.timeout = timeout;
        this.queryBuilder = queryBuilder;
    }

    public String getIndexName() {
        return indexName;
    }

    public void setIndexName(String indexName) {
        this.indexName = indexName;
    }

    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public List<String> getHighlightFieldList() {
        return highlightFieldList;
    }

    public void setHighlightFieldList(List<String> highlightFieldList) {
        this.highlightFieldList = highlightFieldList;
    }

    public int getOffset() {
        return offset;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    public long getTimeout() {
        return timeout;
    }

    public void setTimeout(long timeout) {
        this.timeout = timeout;
    }

    public QueryBuilder getQueryBuilder() {
        return queryBuilder;
    }

    public void setQueryBuilder(QueryBuilder queryBuilder) {
        this.queryBuilder = queryBuilder;
    }

    public SearchType getSearchType() {
        return searchType;
    }

    public void setSearchType(SearchType searchType) {
        this.searchType = searchType;
    }

    public ESQueryRequest addHighlightField(String filed) {
        if (highlightFieldList == null) {
            highlightFieldList = new ArrayList<String>();
        }
        highlightFieldList.add(filed);
        return this;
    }
}
